#ifndef FACTORY_H_
#define FACTORY_H_

#include <boost/thread/mutex.hpp>
#include "PluginFactory.h"

namespace PluginSystem
{

//! Factory. 
/*!
	Thread safe Singleton Holder pre PluginFactory
*/
class Factory
{
	public:
		~Factory()
		{
			delete myFactory;
			myRemoved = true;
		}

		static PluginFactory *Instance()
		{
			if(!myRemoved)
				Build();

			return myFactory;
		}

	private:
		//////////////////////////////////////////////////////////////////////////
		//							MEMBER VARIABLES							//
		//////////////////////////////////////////////////////////////////////////
		static PluginFactory *myFactory;
		static bool myRemoved;
		static boost::mutex myMutex;

		//////////////////////////////////////////////////////////////////////////
		//							MEMBER FUNCTIONS							//
		//////////////////////////////////////////////////////////////////////////
		static void Build()
		{
			if(myFactory == NULL)
			{
				boost::mutex::scoped_lock lock(myMutex);
				if(myFactory == NULL)
				{
					myFactory = new PluginFactory();
				}
			}

			myRemoved = false;
		}

		//Locked Functions
		Factory(void);
		Factory(const Factory&);
		Factory& operator=(const Factory&);

};//end of Factory

}//PluginSystem

#endif//FACTORY_H_
